class Solution {
 /*   
private:
    int a[10001] = {0}, b[10001] = {0}, sum[10002] = {0};
public:
    string addStrings(string num1, string num2) {
        int alen = num1.size(), blen = num2.size();
        // 将字符串逆序放入数组
        for(int i = alen - 1; i >= 0; --i){
            a[alen - 1 - i] = num1[i] - '0';
        }
        for(int j = blen - 1; j >= 0; --j){
            b[blen - 1 - j] = num2[j] - '0';
        }

        int maxlen = alen > blen ? alen : blen;
        
        //模拟加法运算过程
        for(int i = 0; i < maxlen; ++i){
            sum[i] += a[i] + b[i];    // 从低位相加
            sum[i + 1] = sum[i] / 10;  //大于10的数字进位
            sum[i] %= 10;          //如果进位取余，不进位就不变
        }
        if(sum[maxlen]){ ++maxlen; }  // 最高位进位，数字增加一位长度加一
        string retsum;
        for(int i = maxlen - 1; i >= 0; --i){
            retsum.push_back(sum[i] + '0');
            //retsum[maxlen-1-i] = sum[i] + '0';
        }
        return retsum;
    }
*/

//改进版本
public:
    string addStrings(string num1, string num2) { 
        int len1 = num1.size()-1, len2 = num2.size()-1;
        string retsum;
        int sum = 0;   
        while(len1 >= 0 || len2 >= 0 || sum != 0){
            if(len1 >= 0) sum += num1[len1--] - '0';    
            if(len2 >= 0) sum += num2[len2--] - '0';
            retsum += (sum % 10) + '0';
            sum /= 10;
        }
        reverse(retsum.begin(), retsum.end());
        return retsum;
    }
};